class User < ActiveRecord::Base
  has_many :friendships, :dependent => :destroy
  has_many :friends, :through => :friendships, :class_name => 'User'
  has_many :user_favorite_subjects, :dependent => :destroy
  has_many :messages, :dependent => :destroy
  has_many :item_alliances, :dependent => :destroy
  has_many :picture_comments, :dependent => :destroy
  has_many :item_ratings, :dependent => :destroy
  has_many :item_rating_replies, :dependent => :destroy
  
  def after_create
     UserFavoriteSubject.create! :user_id => id, :title => 'Default'
     UserVerify.create! :user_id => id, :verify_code => generateVerifyCode
  end
  
  def generateVerifyCode
    chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    newpass = ""
    1.upto(20) { |i| newpass << chars[rand(chars.size-1)] }
    return newpass    
  end
end
